package com.android.kotlincoroutinemvvmdemo
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import com.android.kotlincoroutinemvvmdemo.base.BaseActivity
import com.android.kotlincoroutinemvvmdemo.databinding.ActivityReflectBinding

class ReflectActivity : BaseActivity<ActivityReflectBinding>() {

    override fun getLayoutId() = R.layout.activity_reflect

    private var mHandler: TTHandler? = null

    override fun init(savedInstanceState: Bundle?) {

        mHandler = TTHandler()

        val message0 = Message.obtain()
        message0.what = MSG0
        mHandler?.sendMessageDelayed(message0, 2000)

        val message1 = Message.obtain()
        message1.what = MSG1
        message1.isAsynchronous = true
        message1.target = null
        mHandler?.sendMessageDelayed(message1, 2000)
    }

    class TTHandler : Handler(Looper.getMainLooper()) {
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            when (msg.what) {
                MSG0 -> {
                    Log.d(TAG, "MSG0--MSG0--MSG0--MSG0")
                }
                MSG1 -> {
                    Log.d(TAG, "MSG1--MSG1--MSG1--MSG1")
                }
            }
        }
    }

    companion object {
        //伴生对象，只能依附类文件存在，不能单独存在。因为kotlin不支持static关键字，作为对static关键字的替换。
        //也是一个静态常量类，构造方法私有。
        const val TAG = "ReflectActivity"

        const val MSG0 = 0x00
        const val MSG1 = 0x01
    }
}